﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace MTQ.Common
{

    public class ApiTonkeyHelper
    {

        public static string GetMD5DecryptMessage(string str)
        {
            string dec = MD5Cryptography.MD5Decrypt(str);
            var tonkeyreg = new Regex("(?<=(tonkey=))[.\\s\\S]*?(?=(endtonkey;;))", RegexOptions.Multiline | RegexOptions.Singleline);
            var messageereg = new Regex("(?<=(message=))[.\\s\\S]*?(?=(endmessage;;))", RegexOptions.Multiline | RegexOptions.Singleline);
            var timereg = new Regex("(?<=(time=))[.\\s\\S]*?(?=(time;;))", RegexOptions.Multiline | RegexOptions.Singleline);

            string tonkey = tonkeyreg.Match(dec).Value.Trim('\"');
            string message = messageereg.Match(dec).Value;
            string time= timereg.Match(dec).Value;
            if (time._ToDatetime() == null) {
                return null;
            }
            return message;

        }


        public static string GetMD5EncryptMessage(string message)
        {
            string str = string.Format("message={0}endmessage;;time={1}time;;", message, System.DateTime.Now.ToShortDateString());
            string result = MD5Cryptography.MD5Encrypt(str);
            return result;
        }

    }


}